#ifndef TUXSPYPANEL_H
#define TUXSPYPANEL_H

#include "TuxSpy_GUI.h"
#include "FusionSpyStruct.h"
#include "TuxedoSite.h"
#include "DBWrapper.h"
#include "AlarmAction.h"

#include <wx/timer.h>
#include <wx/thread.h>

class TuxSpyPanel : public TuxPanel
{
	friend class TuxPanelThread;
public:
	TuxSpyPanel( wxWindow* parent );
	~TuxSpyPanel();
	int InitControl();

	void OnTimer(wxTimerEvent& event);

    void SetSite( Site site);

	TuxedoSystem tuxsys;
	TuxedoStat tuxstat;
	TuxInitBuff tuxinitbuff;

protected:
	int GetLicenseType();
	int SvrDataParser();
	void UpdateControl();
	void UpdateLogWindow(int type);
	int DoAlarmAction();
	int SetAlarmType( wxString svrname, int alarmtype );
	int FilterSvrData( wxString svrname, wxString status, int filtertype);
	void AlarmSvrData();

	void OnSvrFilterCheck( wxCommandEvent& event  );
	void OnQueFilterCheck( wxCommandEvent& event  );
	void OnSvrListColClick( wxListEvent& event );
	void OnSvrFilterApply( wxCommandEvent& event );
	void OnQueFilterApply( wxCommandEvent& event );
	void OnChsServer( wxCommandEvent& event );
	void OnChsQueue( wxCommandEvent& event );
	void OnControl( wxCommandEvent& event );
	void OnAlarmSet(wxCommandEvent& event );
	void OnSocketEvent( wxSocketEvent& event);
	void OnBtnLogClear( wxCommandEvent& event );

private:
	void StartMonitor();
	void StopMonitor();
	
protected:
	TuxedoServerArray tuxsvrarray;
    TuxedoQueueArray tuxquearray;
    TuxedoClientArray tuxcltarray;
	TuxedoServerArray oldtuxsvrarray;
	TuxedoQueueArray oldtuxquearray;
	
	bool m_IsStart;
	bool m_SortByRqDone;

	wxTimer m_timer;
	wxString m_rcvdata;
	wxString m_lastupdate;
	wxInt32 m_nreccount;
	wxString m_svrfilter;
	wxString m_quefilter;

	wxString m_diedsvrname;
	wxString m_longbusysvrname;
	wxString m_longidlesvrname;
	
	int m_chssvrfilter;
	int m_chsquefilter;

	wxFFile m_logfile;
	wxLogStderr *LogFile;

	CDBWrapper dbWrapper;
	CTuxedoSite m_tuxsite;
	TuxAlarm m_tuxalarm;
	Site m_site;
	SysRecList m_sysreclist;
	TuxResource m_tuxresource;

	CAlarmAction alarmaction;

	DECLARE_EVENT_TABLE();
};

//Thread class----------------------        
class TuxPanelThread : public wxThread
{                                   //class containing server thread
public:
	friend class TuxSpyPanel;
    TuxPanelThread(TuxSpyPanel* pPanel){ m_pPanel = pPanel; }
	~TuxPanelThread(){;}
	TuxSpyPanel*   m_pPanel;  //Our server

    virtual ExitCode Entry()        //on run entry method
    {
		m_pPanel->m_rcvdata = m_pPanel->m_tuxsite.ActVsAgent(GETSVRDATA,wxT(""));
		if( m_pPanel->SvrDataParser() > 0 ) {
			m_pPanel->UpdateControl();
			m_pPanel->DoAlarmAction();
		}     
		return 0;
	}
    
    virtual void OnExit() {         //on thread exit method
	   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	   //put here what will thread do on exit
   
    }
}; 

#endif //TUXSPYPANEL_H